/*
 * Created by JFormDesigner on Wed Jun 07 14:18:22 CST 2023
 */

package gui.user;

import gui.register.LoginFrame;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 * @author Liubuzhu
 */
public class UserMainFrame extends JFrame {
    public UserMainFrame(String userId) {
        initComponents(userId);
    }

    private void initComponents(String userId) {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        button1 = new JButton();
        button2 = new JButton();
        button3 = new JButton();
        button4 = new JButton();

        //======== this ========
        setVisible(true);
        setPreferredSize(new Dimension(600, 450));
        setTitle("\u6b22\u8fce\u60a8\uff0c\u4eb2\u7231\u7684\u987e\u5ba2\uff01\uff01\uff01");
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button1 ----
        button1.setText("返回");
        button1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(button1);
        button1.setBounds(245, 185, 100, 45);

        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                dispose();
                LoginFrame loginFrame = new LoginFrame();
            }
        });

        //---- button2 ----
        button2.setText("\u6211\u7684\u8ba2\u5355");
        button2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(button2);
        button2.setBounds(245, 105, 100, 45);

        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    dispose();
                    MyOrderFrame myOrderFrame = new MyOrderFrame(userId);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //---- button3 ----
        button3.setText("\u6211\u7684\u4fe1\u606f");
        button3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(button3);
        button3.setBounds(425, 105, 100, 45);

        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    dispose();
                    MyInfoFrame myInfoFrame = new MyInfoFrame(userId);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //---- button4 ----
        button4.setText("\u6d4f\u89c8\u5546\u54c1");
        button4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
        contentPane.add(button4);
        button4.setBounds(60, 105, 100, 45);

        button4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    dispose();
                    BrowseProductFrame browseProductFrame = new BrowseProductFrame(userId);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //添加背景图片
        JLabel background = new JLabel(new ImageIcon("./image/user/背景2.jpg"));
        background.setBounds(0, 0, 600, 450);
        this.getContentPane().add(background);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private JButton button4;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
    public static void main(String[] args) {
        UserMainFrame userMainFrame = new UserMainFrame("123");
    }
}
